package uk.ac.nott.cs.g53dia;
/**
 * Action to lay an egg in a nest.
 * <p>
 * To perform the action, the bee must be at the same location as the nest
 * and the nest must contain at least EGG_COST units of energy.
 * 
 * @author Neil Madden.
 */

/*
 * Copyright (c) 2005 Neil Madden (nem@cs.nott.ac.uk)
 * 
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

public class LayEggAction implements Action {


    public LayEggAction() { }

    public void execute(Environment env, Bee bee)
        throws ActionFailedException
    {
        Cell c = env.getCell(bee.getPosition());
        if (c instanceof Nest) {
            Nest n = (Nest)c;
            if (n.foodSupply() < Nest.EGG_COST) {
                throw new ActionFailedException
                    ("LayEgg: not enough food in nest");
            }
            n.layEgg();
        } else {
            throw new ActionFailedException("LayEgg: not on a nest");
        }
        // Minimal energy cost - bee has already lost a lot by depositing
        // food.
        bee.eggs_laid++;
        bee.useEnergy(1);
    }

    public String toString() {
        return "Lay egg";
    }
}
